package com.zhou.basics.business.brand;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhou.basics.common.core.Result;
import com.zhou.basics.common.core.ResultPage;
import com.zhou.basics.common.enums.ResultCode;
import com.zhou.basics.model.goods.Brand;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ProjectName: tsqingcheng
 * @ClassName: BrandController
 * @Time: 2020/2/28
 * @Author: zhou24
 * @Description:
 * @Experience:
 */
@RestController
@RequestMapping("/brand")
public class BrandController {

    @Resource
    private BrandService brandService;

    @GetMapping("/queryAll")
    public Result queryAll(){
        List<Brand> list = brandService.queryAll();
        return null==list?new Result().setCode(ResultCode.FAIL):new Result().success(list);
    }

    @GetMapping("/queryPage")
    public Result queryPage(@RequestParam(defaultValue = "1") int pageNum,
                            @RequestParam(defaultValue = "10") int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Brand> pageInfo = new PageInfo<>(brandService.queryPage(),10);
        return null==pageInfo?new Result().setCode(ResultCode.FAIL):new Result().success(pageInfo);
    }

}
